#ifdef _WIN32
#include <windows.h>
#endif

#include "GLee.h"
#include <GL/glu.h>

#include "Entity.h"
#include "Scene.h"

Entity::Entity(void)
    : m_canBeRemoved(false), m_position(), m_pixelsSize(), m_rotationAngles()
{
}

Entity::Entity(boost::shared_ptr<Scene> scene)
    : m_canBeRemoved(false), m_scene(scene), m_position(), m_pixelsSize(), m_rotationAngles()
{
}

Entity::~Entity(void)
{

}

bool Entity::canBeRemoved(void) const
{
    return m_canBeRemoved;
}

void Entity::destroy(void)
{
    m_canBeRemoved = true;
    onDestroy();
}

void Entity::prepare(float dt)
{
    onPrepare(dt);
}

void Entity::render(void) const
{
    onRender();
}

void Entity::postRender(void)
{
    onPostRender();
}

bool Entity::initialize(void)
{
    return onInitialize();
}

void Entity::shutdown(void)
{
    onShutdown();
}

void Entity::applyRotation(void) const
{
    if (m_rotationAngles.x != 0.0f)
    {
        glRotatef(m_rotationAngles.x, 1.0f, 0.0f, 0.0f);
    }
    if (m_rotationAngles.y != 0.0f)
    {
        glRotatef(m_rotationAngles.y, 0.0f, 1.0f, 0.0f);
    }
    if (m_rotationAngles.z != 0.0f)
    {
        glRotatef(m_rotationAngles.z, 0.0f, 0.0f, 1.0f);
    }
}

bool Entity::isOutOfScreen(void) const
{
    bool isOut = false;
    Dimension screenSize = m_scene->getScreenSize();
    if ((m_position.x < 0.0f) || (m_position.x > screenSize.width))
    {
        isOut = true;
    }
    else if ((m_position.y < 0.0f) || (m_position.y > screenSize.height))
    {
        isOut = true;
    }
    
    return isOut;
}
